package com.gzw.dms.activity;

import android.content.Context;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Spinner;
import android.widget.TextView;

import com.gzw.dms.MyApplication;
import com.gzw.dms.R;
import com.gzw.dms.base.BaseActivity;
import com.gzw.dms.base.BaseSpinnerAdapter;
import com.gzw.dms.bean.SpinnerInfo;
import com.gzw.dms.bean.UserInfo;

import java.util.ArrayList;

public class BackOrderTJActivity extends BaseActivity {
    private Toolbar toolbar;
    private EditText et_num,et_dress,et_fhkh,et_select_sljg;
    private TextView tv_select_end,tv_select_ydlx;
    private Context mContext;
    private Button btn_select;
    private Intent mIntent;
    private Spinner et_select_ydlx;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    @Override
    protected void setContentView() {
        setContentView(R.layout.activity_back_order_tj);

    }

    @Override
    protected void initViews() {
        toolbar = (Toolbar) findViewById(R.id.toolbar);
        et_num=(EditText) findViewById(R.id.et_select_num);
        et_dress=(EditText) findViewById(R.id.et_select_dress);
        et_fhkh=(EditText) findViewById(R.id.et_select_fhkh);
        et_select_sljg=(EditText) findViewById(R.id.et_select_sljg);
        btn_select=(Button)findViewById(R.id.btn_select);
        tv_select_end=(TextView) findViewById(R.id.tv_select_end);

        et_select_ydlx=(Spinner) findViewById(R.id.et_select_ydlx);
        tv_select_ydlx=(TextView) findViewById(R.id.tv_select_ydlx);
    }

    @Override
    protected void initData() {
        mContext = this;
        toolbar.setTitle("条件查询");
        setSupportActionBar(toolbar);
        mIntent = getIntent();
        UserInfo userInfo = MyApplication.getUserInfo();
        if (userInfo.getFlag().equals("1")) {
            et_select_ydlx.setVisibility(View.GONE);
            tv_select_ydlx.setVisibility(View.GONE);
        }
        ArrayList ls = new ArrayList();
        ls.add(new SpinnerInfo("0", "退货"));
        ls.add(new SpinnerInfo("1", "调拨"));
        BaseSpinnerAdapter Adapter = new BaseSpinnerAdapter(mContext, ls);
        et_select_ydlx.setAdapter(Adapter);

    }

    @Override
    protected void initEvents() {
        toolbar.setNavigationOnClickListener(new myOnClick());
        btn_select.setOnClickListener(new myOnClick());
    }
    class myOnClick implements View.OnClickListener {
        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            switch (v.getId()) {
                case R.id.btn_select:
                    sendData();
                    break;
                default:
                    finish();
                    break;
            }
        }
    }

    private void sendData(){

        Intent mIntent = new Intent();
        //把返回数据存入Intent
        mIntent.putExtra("order_num",et_num.getText().toString());
        mIntent.putExtra("et_dress",et_dress.getText().toString());
        mIntent.putExtra("custom_name",et_fhkh.getText().toString());
        mIntent.putExtra("sljg",et_select_sljg.getText().toString());
        SpinnerInfo spinnerInfo = (SpinnerInfo) et_select_ydlx.getSelectedItem();
        String type = spinnerInfo.getId();
        mIntent.putExtra("ydlx",type);
        //设置返回数据
        setResult(2, mIntent);
        finish();
    }
}
